package thread;

/**
 * @author Bboy Dday
 * @create 2020:06:15--18:45
 */

class Account1{
    private double balance;
    public Account1( double balance ){
        this.balance = balance;
    }

    public void deposit( double amt ){
        if ( amt > 0 ){
            try {
                Thread.sleep( 1000 );
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            balance += amt;
            System.out.println( Thread.currentThread().getName() + "存款成功。余额：" + balance );
        }

    }
}

class Customer1 implements Runnable{
    private Account1 acct1;

    public Customer1( Account1 acct1 ){
        this.acct1 = acct1;
    }

    @Override
    public void run() {
        for (int i = 0; i < 3; i++) {

            acct1.deposit( 1000 );

        }
    }
}

public class AccountTest1 {
    public static void main(String[] args) {
        Account1 acct1 = new Account1(0);
        Customer1 c1 = new Customer1( acct1 );

        Thread t1 = new Thread( c1 );
        Thread t2 = new Thread( c1 );

        t1.setName( "甲" );
        t2.setName( "乙" );

        t1.start();
        t2.start();
    }
}
